package grpc

import (
	"auth/config"
	"auth/server/grpc/middleware"
	"gitee.com/ai_camera/proto/device"
	"github.com/asim/go-micro/plugins/client/grpc/v4"
	"github.com/asim/go-micro/plugins/registry/etcd/v4"
	"go-micro.dev/v4/client"
	"go-micro.dev/v4/registry"
	"go-micro.dev/v4/selector"
	"time"
)

// UserClient example client, in reality, you should replace it with your own grpc client
//var UserClient example.UserService

var DeviceClient device.DeviceService

func Init() func() {
	//UserClient = example.NewUserService("example.UserService", config.MicroService.Client())

	regCenter := etcd.NewRegistry(registry.Addrs(config.EtcdAddr))
	DeviceClient = device.NewDeviceService("device-grpc", grpc.NewClient(
		client.Registry(regCenter),
		client.Retries(0),
		client.DialTimeout(time.Second*8),
		client.RequestTimeout(time.Second*10),
		client.WrapCall(middleware.ClientTraceWrapper()),
		client.Selector(selector.NewSelector(
			selector.Registry(regCenter),
			selector.SetStrategy(selector.RoundRobin),
		)),
	))

	return func() {}
}
